home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7788 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  36 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.netins.net!isac!gg
  3. From: gg@isac.hces.com (Greg Goodrich)
  4. Subject: Re: about free()
  5. Message-ID: <1996Feb28.195932.10666@isac.hces.com>
  6. Organization: Health Care Expert Systems
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. References: <31333454.167E@mashie.ece.jhu.edu>
  9. Date: Wed, 28 Feb 1996 19:59:32 GMT
  10.  
  11. chenyang@mashie.ece.jhu.edu wrote:
  12. : Hi, there,
  13.  
  14. :      I have a simple question here.
  15.  
  16. :      I have a function say newarrary() which mallocs an array inside and
  17. : returns a pointer to this arrary. In another function foo.c, the result
  18. : of newarray() is assigned to a pointer ptr. Now after some operations on
  19. : this array. I use free(ptr) to free the memory allocated by newarrary().
  20. : My question is whould this cause a problem, since free() is not freeing
  21. : the same pointer which is allocated by the malloc() although this
  22. : pointer point to the same memory.
  23.  
  24. The only thing that is important for freeing a dynamically allocated
  25. variable is the address of the allocated space.  The ptr merely contains
  26. this address, and it does not matter what variable you use to free the
  27. space as long as you are passing the same address to the free call that
  28. the malloc call returned.
  29.  
  30. Greg.
  31. -- 
  32. _______________________________________
  33.     Greg Goodrich - gg@hces.com
  34.     Software Engineer
  35.     PACE Health Management Systems
  36.